package com.ge.med.cchelper.util.ftp;

import com.ge.med.cchelper.bean.Host;
import com.ge.med.cchelper.util.LogUtil;

public class FTPFactory {
	
  /*1=Apache, 2= SFtp*/
  public static int selectionFTPProduce = 1;	
	
  public static FtpHelper getConnectionInstance(Host host, String path) throws Exception{
	  FtpHelper ftphelp = null;
	  
	  ftphelp = new FtpApache();
	  if(!ftphelp.connectServer(host, path)){
		  ftphelp = new SFtpHelper();
		  if(!ftphelp.connectServer(host, path)){
			  selectionFTPProduce = 0;
			  throw new Exception("try to connect ftp server, but failing.");
		  }else{
			  selectionFTPProduce = 2;
			  LogUtil.out("[FTP]file protocol: SFTP");
		  }
	  }else{
		  selectionFTPProduce = 1;
		LogUtil.out("[FTP]file protocol: FTP");
	  }
	  
	  return ftphelp;
  }
  
  public static FtpHelper getConnectionInstance(Host host, String path, int ftpProduce)throws Exception{
	  FtpHelper ftphelp = null;
	  if(ftpProduce == 1){
		  LogUtil.out("[FTP]file protocol: FTP");
		  ftphelp = new FtpApache();
	  }else{
		  LogUtil.out("[FTP]file protocol: SFTP");
		  ftphelp = new SFtpHelper();
	  }
	  ftphelp.connectServer(host, path);
	  return ftphelp;
  }
	
}
